import request from '@/utils/request'
interface ExtraData {
  webShowFlag: number // 是否在web端展示此菜单 1：展示，2：不展示
}

export interface ModuleInterface {
  id: string
  parentId: string | undefined
  appId: string
  data: any // `data` json NULL
  type: string //   '类型 1:文件夹 2:api接口 3:model类型'
  name: string //  '接口路径'
  createTime?: string
  updateTime?: string
  delFlag?: 0 | 1 //   '删除标识（0 未删除 1已删除）'
  createBy?: string
  updateBy?: string
  remarks?: string
  sort: number //   '排序'
  extra?: ExtraData // 额外数据
}

export interface ModuleTreeInterface extends ModuleInterface {
  children: ModuleTreeInterface[]
}

export function getModuleList (params?: any) {
  return request({
    url: '/v1/system-application-service/list',
    method: 'get',
    params
  })
}

export function addModule (data: ModuleInterface) {
  return request({
    url: '/v1/system-application-service/add',
    method: 'post',
    data
  })
}

export function moduleDetail (id: string) {
  return request({
    url: `/v1/system-application-service/getById`,
    method: 'get',
    params: {
      id
    }
  })
}

export function updateModule (data: any) {
  return request({
    url: '/v1/system-application-service/update',
    method: 'post',
    data
  })
}

export function deleteModule (id: string) {
  return request({
    url: `/v1/system-application-service/delete`,
    method: 'post',
    data: {
      id
    }
  })
}

export function getAllModule (params?: any) {
  return request({
    url: `/v1/system-application-service/modelList`,
    method: 'get',
    params
  })
}

export function copyModule (params?: any) {
  return request({
    url: `/v1/system-application-service/copy`,
    method: 'post',
    params
  })
}

export function getCreateTableSql (params:any) {
  return request({
    url: `/v1/system-sql/getTableSql`,
    method: 'get',
    params
  })
}
